﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Dwg_output
{
    class Output_Bom
    {

        public string db_path;
        public Dictionary<int, string> Dict_sys_jigui;
        public Dictionary<int, string> Dict_jigui;
        public Dictionary<string, int> nameCounts;

        public int max_num;
        public  Output_Bom(string path)
        {
            db_path = path;

        }
        public Dictionary<int, string> readjigui_Dictionary()
        {   
           
          
            Dict_sys_jigui = Wire_ReadSQL.Read_Sys_Jigui_Dictionary(db_path, 1);//读取系统机柜键值
            Dict_jigui = Wire_ReadSQL.Read_Jigui_Dictionary(db_path, 1);

            max_num = Wire_ReadSQL.Read_Max_card_id(db_path, "1");
            return Dict_jigui;
        }

        public List<Dictionary<string, int>> read1()
        {
            List<Dictionary<string, int>> Dict_list = new List<Dictionary<string, int>>();
            for (int i = 0; i < Dict_jigui.Keys.Count; i++)//不同的机柜
            {


                Dictionary<string, int> nameCounts = new Dictionary<string, int>();
                for (int j = 0; j <= max_num; j++)//这个循环为遍历不同卡件的所有位号
                {
                    string value;
                    if (Dict_jigui.TryGetValue(i+1, out value))
                    {
                        // 如果键存在于字典中，输出键和值  
                        Console.WriteLine($"The key {i + 1} has the value {value}.");
                     

                    }
                    else
                    {
                        // 如果键不存在于字典中，输出相应的消息  
                        Console.WriteLine($"The key {i + 1} was not found in the dictionary.");
                    }



                    List<List<string>> tag = Wire_ReadSQL.ReadTagFromSql(db_path, j, i+1);

                    Num_Tag num_Tag = new Num_Tag();

                    if(tag.Count == 0)//获取到当前卡件内的位号为0时
                    {
                        continue;
                    }

                    string name = tag[0][num_Tag.termail_board];


                    if (!tag[0][num_Tag.termail_board].Equals(""))
                    {
                        // 检查字典中是否已经有了这个名字  
                        if (nameCounts.ContainsKey(name))
                        {
                            // 如果已经有了，增加对应的计数器  
                            nameCounts[name]++;
                        }
                        else
                        {
                            // 如果还没有，添加到字典中并设置计数器为1  
                            nameCounts.Add(name, 1);
                        }



                    }
                  

                }
                Dict_list.Add(nameCounts);

            }


            return Dict_list;








        }


    }
}
